$(function(){
  window.Interface.tracking('幸运抽奖', '查看抽奖记录','我的抽奖机会');
  $(".settab li").on("click",function(){
    var index = $(this).index()+1;
    $(".settab-conn-"+index).show().siblings(".settab-conn").hide();
    $(this).addClass("current").siblings("li").removeClass("current");
    if(index===1){
      window.Interface.tracking('幸运抽奖', '查看抽奖记录','我的抽奖机会');
    }else{
      window.Interface.tracking('幸运抽奖', '查看抽奖记录','抽奖规则');
    }
  });




});

window.Interface.chanceList({},function(res){
  creatChanceList("#list-chance",res.chanceList);
});



function creatChanceList(obj,data){

  var $obj = $(obj);
  $obj.empty();
  var first = data.length;
  var defNum = 5;
  if(data.length >= defNum){
    first = defNum;
  }
  for(var i = 0; i< first; i++){
    var div = '    <div class="list-chance">'+
              '      <h3 class="tit"><i class="icon-help icon-'+ data[i].type +'"></i><span>'+ data[i].tit +'</span></h3>'+
              '      <p>获得日期：'+data[i].date+'</p>'+
              '      <p>编号：'+data[i].no+'</p>'+
              '      <span>'+data[i].desc+'</span>'+
              '    </div>'+
              '    <hr>';
   $obj.append(div);
  }


  if(data.length > defNum){
    $obj.append('<div class="more"><span>加载更多</span><i></i></div>');

    $(".more",$obj).on("click",function(){
        for(var i = first; i< data.length; i++){
            var div = '    <div class="list-chance">'+
                    '      <h3 class="tit"><i class="icon-help icon-'+ data[i].type +'"></i><span>'+ data[i].tit +'</span></h3>'+
                    '      <p>获得日期：'+data[i].date+'</p>'+
                    '      <p>编号：'+data[i].no+'</p>'+
                    '      <span>'+data[i].desc+'</span>'+
                    '    </div>'+
                    '    <hr>';
        $obj.append(div);
      }
      $(".more",$obj).hide();
    });
    

  }
  




}


